window.onload = function () {
    var toprev = document.querySelector('.toprev')
    toprev.onclick = () => history.back()


    // 查询所有订单显示在页面上
    request({
        url: '/front/api/order/getall/' + getCookie('userId'),
        headers: {
            Authorization: localStorage.getItem('token')
        }
    }).then(res => {
        let orders = document.querySelector('.orders ul')
        // console.log(res);
        let { error_code, msg } = res
        if (error_code === 200) {
            let orderHTML = ''
            res.data.orders.forEach(order => {
                let code = order.code + ''
                code = '0'.repeat(4 - code.length) + code
                orderHTML += `
                <li>
                    <p>
                        <span>订单号：${order.orderNo} <i class="iconfont icon-youjiantou"></i></span> 
                        <span>${order.payStatus}</span>
                    </p>
                    <p>日期：${new Date(order.createdAt).toLocaleString().replace(/\//g, '.')}</p>
                    <p>
                        <i>${order.eatWay}</i>
                        <span>${order.dishName}等${order.dishNum}件商品</span>
                        <b>￥${order.totalPrice}</b>
                    </p>
                    <p>取餐码：${code}</p>
                </li>
            `
            })
            orders.innerHTML = orderHTML
        }
    })
}